home *** CD-ROM | disk | FTP | other *** search
- /*
- A very simple echo tcp client.
- Show how to make a basic connection to a tcp service.
- To test it on localhost, be sure echo/tcp is enabeld
- in the services and inetd database, then write
- rx echotcp localhost.
- */
-
- l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
- if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
-
- prg = ProgramName("NOEXT")
-
- if ~RMH_ReadArgs("HOST/A") then do
- call PrintFault()
- exit
- end
-
- addr = resolve(parm.0.value)
- if addr=="-1" then call err "no host <"parm.0.value">"
-
- if ~getservbyname("SE","echo","tcp") then call err "echo tcp service not found"
-
- sin.ADDRFAMILY = "INET"
- sin.ADDRADDR = addr
- sin.ADDRPORT = SE.SERVPORT
-
- sock = socket("INET","STREAM","IP")
- if sock<0 then call err "no socket ("errno()")"
-
- if connect(sock,"SIN")<0 then call err "connect error ("errno()")"
-
- REQUEST = "echo service test"
- res = send(sock,REQUEST)
- if res~=length(REQUEST) then call err "send error ("errno()")"
-
- len = recv(sock,"BUF",256)
- if len<0 then call err "recv error ("errno()")"
-
- say buf
- call CloseSocket(sock)
- exit
-
- err: procedure expose prg
- parse arg msg
- say prg":" msg
- exit
-